//
//  XFStatueCell.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/16.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFStatueCell.h"
#import "XFOriginalView.h"
#import "XFBottomView.h"
#import "XFRetweeteView.h"

@interface XFStatueCell ()

@property(nonatomic, weak) XFOriginalView *originalView;

@property(nonatomic, weak) XFBottomView *bottomView;

@property(nonatomic, weak) XFRetweeteView *retweeteView;

@property(nonatomic, strong) MASConstraint *bottomContraint;

@end

@implementation XFStatueCell

- (void)setStatues:(XFStatues *)statues {

  _statues = statues;

  self.originalView.statues = statues;
  
    [self.bottomContraint uninstall];
  if (statues.retweetes != nil) {
      self.retweeteView.retweetes = statues.retweetes;
      self.retweeteView.hidden = NO;
      [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
          
          self.bottomContraint = make.top.equalTo(self.retweeteView.mas_bottom)
          .offset(kStatueCellMargin);
          
      }];
  } else {
      self.retweeteView.hidden = YES;
      [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
          
          self.bottomContraint = make.top.equalTo(self.originalView.mas_bottom)
          .offset(kStatueCellMargin);
        
      }];
  }
}

// 1.重写 init 方法

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {

  if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
      self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setupUI];
    [self setupFrame];
  }
  return self;
}
// 2. setupUI添加子控件
- (void)setupUI {
  //添加原创微博
  XFOriginalView *originalView = [[XFOriginalView alloc] init];
  [self.contentView addSubview:originalView];
  self.originalView = originalView;
  //添加底部
  XFBottomView *bottomView = [[XFBottomView alloc] init];
  [self.contentView addSubview:bottomView];
  self.bottomView = bottomView;
  //添加转发微博
  XFRetweeteView *retweeteView = [[XFRetweeteView alloc] init];
  [self.contentView addSubview:retweeteView];
  self.retweeteView = retweeteView;
     
}

// 3. setupFrame添加子控件约束
- (void)setupFrame {
  [self.originalView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.top.equalTo(self.contentView);
    //    make.height.equalTo(@100);
  }];
  [self.retweeteView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.originalView.mas_bottom);
    make.left.right.equalTo(self.originalView);

  }];

  [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.equalTo(self.originalView);
    self.bottomContraint = make.top.equalTo(self.retweeteView.mas_bottom);
    make.height.equalTo(@40);
  }];

  [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.bottomView.mas_bottom);
    make.left.right.top.equalTo(self);
  }];
}

@end
